<?php

mysql_connect("localhost", "root", "vertrigo");
mysql_select_db("tdc");
$table = "students";
if (!empty($_POST["submit"])) {
    mysql_query("UPDATE $table SET name='" . $_POST['name'] ."' WHERE id='" . $_POST['id'] . "'");
    echo "Record " . $_POST['id'] . " successfully updated.<br />";
    echo "<a href='index.php'>Back to main page</a>";
}
$sql = "SELECT * FROM $table";
$results = mysql_query($sql);
while ($row = mysql_fetch_assoc($results)) {
    $id_array[] = $row["id"];
    $name_array[] = $row["name"];
}
echo "
       <table border='1'>
        <tr>
         <th>ID</th>
         <th>Name</th>
         <th>&nbsp;</th>
        </tr>";
for ($i = 0; $i < count($id_array); $i++) {
    $id = $id_array[$i];
    $name = $name_array[$i];
 
    echo "<form action='#' method='post'>
        <tr>
         <td><input type='text' name='id' value='$id' readonly></td>
         <td><input type='text' name='name' value='$name'></td>
  
         <td><input type='submit' name='submit[]' value='Update'></td>
        </tr>
       </form>";
}
echo "</table>";
?>
